@using BlazorApp.Pages.Common
@using BlazorApp.Service.k8s
@using k8s.Models
@inherits BlazorApp.Pages.Common.PageBase

@if (_isMetricsServerReady)
{
    <Divider Orientation="left" Style="font-weight:bold">@L["Container"] @L["Metrics"]</Divider>
    <GridRow Class="grid-table ">
        <GridCol Span="8" Flex=@("160px")>@L["Container"] @L["Name"]</GridCol>
        <GridCol Span="8">@L["CPU"]</GridCol>
        <GridCol Span="8">@L["Memory"]</GridCol>
    </GridRow>
    @foreach (var item in Containers)
    {
        <GridRow Class="grid-table grid-table-first-row ">
            <GridCol Span="8" Flex=@("160px")>@item.Name</GridCol>
            <GridCol Span="8">
                <MetricView ResourceType="Container" ItemName="@PodName" ContainerName="@item.Name" MetricType="cpu"></MetricView>
            </GridCol>
            <GridCol Span="8">
                <MetricView ResourceType="Container" ItemName="@PodName" ContainerName="@item.Name" MetricType="memory"></MetricView>
            </GridCol>
        </GridRow>
    }
}

@code {


    [Parameter] public string PodName { get; set; }

    [Parameter] public IList<V1Container> Containers { get; set; }

    [Inject] private IMetricsService MetricsService { get; set; }

    private bool _isMetricsServerReady;

    protected override async Task OnInitializedAsync()
    {
        _isMetricsServerReady = await MetricsService.MetricsServerReady();
        await base.OnInitializedAsync();
    }

}
